package com.order.promotion.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.order.promotion.domain.OrderPromotion;
import com.order.promotion.service.IOrderPromotionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 食品宣传Controller
 * 
 * @author huhu
 * @date 2020-08-29
 */
@Controller
@RequestMapping("/order/promotion")
public class OrderPromotionController extends BaseController
{
    private String prefix = "order/promotion";

    @Autowired
    private IOrderPromotionService orderPromotionService;

    @RequiresPermissions("order:promotion:view")
    @GetMapping()
    public String promotion()
    {
        return prefix + "/promotion";
    }

    /**
     * 查询食品宣传列表
     */
    @RequiresPermissions("order:promotion:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderPromotion orderPromotion)
    {
        startPage();
        List<OrderPromotion> list = orderPromotionService.selectOrderPromotionList(orderPromotion);
        return getDataTable(list);
    }

    /**
     * 导出食品宣传列表
     */
    @RequiresPermissions("order:promotion:export")
    @Log(title = "食品宣传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderPromotion orderPromotion)
    {
        List<OrderPromotion> list = orderPromotionService.selectOrderPromotionList(orderPromotion);
        ExcelUtil<OrderPromotion> util = new ExcelUtil<OrderPromotion>(OrderPromotion.class);
        return util.exportExcel(list, "promotion");
    }

    /**
     * 新增食品宣传
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存食品宣传
     */
    @RequiresPermissions("order:promotion:add")
    @Log(title = "食品宣传", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderPromotion orderPromotion)
    {
        return toAjax(orderPromotionService.insertOrderPromotion(orderPromotion));
    }

    /**
     * 修改食品宣传
     */
    @GetMapping("/edit/{promotionId}")
    public String edit(@PathVariable("promotionId") Long promotionId, ModelMap mmap)
    {
        OrderPromotion orderPromotion = orderPromotionService.selectOrderPromotionById(promotionId);
        mmap.put("orderPromotion", orderPromotion);
        return prefix + "/edit";
    }

    /**
     * 修改保存食品宣传
     */
    @RequiresPermissions("order:promotion:edit")
    @Log(title = "食品宣传", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderPromotion orderPromotion)
    {
        return toAjax(orderPromotionService.updateOrderPromotion(orderPromotion));
    }

    /**
     * 删除食品宣传
     */
    @RequiresPermissions("order:promotion:remove")
    @Log(title = "食品宣传", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderPromotionService.deleteOrderPromotionByIds(ids));
    }
}
